package com.kanas.webak.organization.repository;

import java.util.Date;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.kanas.webak.organization.domain.Calendar;
import com.kanas.webak.organization.domain.Organization;

public interface CalendarRepository extends JpaRepository<Calendar,String> {
	Page<Calendar> findByOrganizationAndSortNumberNotNullOrderBySortNumberDesc(Organization org,Pageable pageable);
	Page<Calendar> findByOrganizationAndBeginDateBetweenAndSortNumberNotNullAndRuleFlagOrderBySortNumberDesc(Organization org,Date date1,Date date2,Boolean ruleFlag, Pageable pageable);
	List<Calendar> findByOrganizationAndBeginDateBetweenAndSortNumberNotNullAndRuleFlagOrderBySortNumberDesc(Organization org,Date date1,Date date2,Boolean ruleFlag);
	List<Calendar> findByOrganizationAndBeginDateBetweenAndRuleFlagAndWorkdayFlag(Organization org,Date date1,Date date2,Boolean ruleFlag,Boolean workFlag);
	@Query("select c from KanasCalendar c where c.organization=?1 and ((c.beginDate between ?2 and ?3 ) or (c.endDate between ?4 and ?5)) and c.ruleFlag=?6 ")
	List<Calendar> findSchedule(Organization org,Date date1,Date date2,Date date3,Date date4,Boolean ruleFlag);
	Calendar findByIdAndRuleFlag(String id,Boolean flag);
	@Query("select Max(c.sortNumber) from KanasCalendar c")
	List<Integer> findMaxSortNumber();
}
